import { defHttp } from '/@/utils/http/axios';
import {
  RoleAuthorizeModel,
  RoleListModel,
  RoleListQueryParam,
  RoleSaveModel,
  RoleUpdateModel,
  SimpleRoleModel,
} from '../model';
import { IdModel } from '/@/api/model/baseModel';
import { Id } from '/@/model/Id';

enum Api {
  GetAll = '/role/all',
  GetList = '/role/find',
  Save = '/role/save',
  Update = '/role/update',
  Del = '/role/delete',
  GetPermissions = '/role/permissions',
  Authorize = '/role/authorize',
}

/**
 * @description: 查询所有角色
 */
export const geAllList = () => {
  return defHttp.get<SimpleRoleModel[]>({ url: Api.GetAll });
};

/**
 * @description: 角色列表
 */
export const getList = (params: RoleListQueryParam) => {
  return defHttp.get<RoleListModel>({ url: Api.GetList, params });
};

/**
 * @description: 保存角色
 */
export const save = (params: RoleSaveModel) => {
  return defHttp.post<RoleSaveModel>({
    url: Api.Save,
    params,
  });
};

/**
 * @description: 更新角色信息
 */
export const update = (params: RoleUpdateModel) => {
  return defHttp.post<RoleUpdateModel>({
    url: Api.Update,
    params,
  });
};

/**
 * @description: 删除角色
 */
export const del = (params: IdModel) => {
  return defHttp.delete<IdModel>({
    url: `${Api.Del}?id=${params.id}`,
  });
};

/**
 * @description: 角色权限
 */
export const getPermission = (params: Id) => {
  return defHttp.get<string[]>({ url: Api.GetPermissions, params });
};

/**
 * @description: 授权
 */
export const authorize = (params: RoleAuthorizeModel) => {
  return defHttp.post({
    url: Api.Authorize,
    params,
  });
};
